package com.hwd.srb.core.enmu;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.Arrays;

/**
 * @author 黄伟东/Victor
 * @date 2022/3/21 21:30
 * @Description 用户状态枚举类
 */
@NoArgsConstructor
@AllArgsConstructor
@Getter
public enum UserStatusEnum {

    LOCKED(0, "锁定"),
    NORMAL(1, "正常"),
    ;

    @EnumValue
    private Integer status;

    @JsonValue
    private String msg;

    @Override
    public String toString() {
        return this.msg;
    }

    public static String getMsgByStatus(int status) {
        return Arrays.stream(UserStatusEnum.values())
                .filter(obj -> status == obj.getStatus())
                .findFirst()
                .map(UserStatusEnum::getMsg)
                .orElse("");
    }

    public static UserStatusEnum getEnumByStatus(int status) {
        return Arrays.stream(UserStatusEnum.values())
                .filter(obj -> obj.getStatus() == status)
                .findFirst().orElse(null);
    }
}
